package com.qk.mapper;

import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {

    /*
    * 查询用户列表
    * */
    List<User> selectList(UserDto userDto);

    /*
    * 添加用户
    * */
    @Insert("insert into user(username, password, name, phone, email, gender, status, dept_id, role_id, " +
            "image, remark, create_time, update_time) values (#{username}, #{password}, #{name}, #{phone}, " +
            "#{email}, #{gender}, #{status}, #{deptId}, #{roleId}, #{image}, #{remark}, #{createTime}, #{updateTime}) " )
    void insert(User user);

    /*
    * 批量删除用户
    * */
    void deleteByIds(List<Integer> ids);

    /*
    * 根据id查询用户
    * */
    @Select("select * from user where id = #{id}")
    User selectById(Integer id);

    /*
    * 根据id修改用户
    * */
    void update(User user);

    /*
    * 查询所有用户
    * */
    @Select("select * from user")
    List<User> selectAll();

    /*
    * 根据角色查询用户
    * */
    @Select("select u.* from user u ,role r where u.role_id = r.id and u.status=1 and r.label = #{lable}")
    List<User> selectByRole(String roleLabel);

    /*
    * 根据部门查询用户
    * */
    @Select("select u.* from user u ,dept d where u.dept_id = d.id and u.status=1 and d.status = 1 and d.id = #{id}")
    List<User> selectByDept(Integer deptId);

    /*
    * 根据用户名查询用户
    * */
    @Select("select u.* ,r.label roleLabel from user u left join role r on r.id = u.role_id where u.username = #{username}")
    User selectByUsername(String username);
}
